package com.pty.demo.structural.composite;

import com.google.common.collect.Lists;

import java.util.List;

/**
 * @author pengty
 * @date 2020/3/12
 */
public class ConcreteCompositeCompany extends AbstractCompanyComponent {

    List<AbstractCompanyComponent> companyList = Lists.newArrayList();

    public ConcreteCompositeCompany(String name) {
        super(name);
    }

    @Override
    public void add(AbstractCompanyComponent component) {
        this.companyList.add(component);
    }

    @Override
    public void remove(AbstractCompanyComponent component) {
        this.companyList.remove(component);
    }

    @Override
    public AbstractCompanyComponent getChildren(int depth) {
        // 输出树形结构
        for (int i = 0; i < depth; i++) {
            System.out.print('-');
        }
        System.out.println(name);

        // 下级遍历
        for (AbstractCompanyComponent component : companyList) {
            component.getChildren(depth + 1);
        }
        return null;
    }

    @Override
    public void operation() {

    }
}
